{#
This file is part of EC-CUBE

Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.

http://www.ec-cube.co.jp/

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
#}
{% extends 'default_frame.twig' %}

{% set menus = ['order', 'order_master'] %}

{% block title %}受注管理{% endblock %}
{% block sub_title %}メール通知{% endblock %}

{% form_theme form 'Form/bootstrap_3_horizontal_layout.html.twig' %}

{% block javascript %}
<script>
$(function() {
    $('#template-change').on('change', function() {
        $('#mode').val('change');
        $('#order-mail-form').submit();
        return false;
    });


    $('#mailModal').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var recipient = button.data('whatever');
        var modal = $('#mailModal');

        $.ajax({
            url: "{{ url('admin_order_mail_view') }}",
            cache: false,
            data: {
                'id' : recipient
            },
        }).done(function(data, textStatus, jqXHR){
            modal.find('.modal-body').html(data);
        }).fail(function(data, textStatus, errorThrown){
            modal.find('.modal-body').text('取得に失敗しました。');
        });
    });

});
</script>
{% endblock javascript %}

{% block main %}

{% if MailHistories %}
<div id="history_wrap" class="row">
    <div id="history_box" class="col-md-9">
        <div id="history_box_body" class="box">
            <div id="history_box__header" class="box-header">
                <h3 class="box-title">メール配信履歴</h3>
            </div><!-- /.box-header -->
            <div id="history_box__body" class="box-body no-padding">
                <div id="history_box__list_box" class="table_list">
                    <div id="history_box__list" class="table-responsive with-border">
                        <table class="table table-striped">
                            <thead>
                                <tr id="history_box__item_header">
                                    <th id="history_box__header_send_date">処理日</th>
                                    <th id="history_box__header_mail_template">通知メール</th>
                                    <th id="history_box__header_subject">件名</th>
                                </tr>
                            </thead>
                            <tbody>
                            {% for MailHistory in MailHistories %}
                                <tr id="history_box__item--{{ MailHistory.id }}">
                                    <td id="history_box__send_date--{{ MailHistory.id }}">{{ MailHistory.send_date|date_format }}</td>
                                    <td id="history_box__mail_template--{{ MailHistory.id }}">{{ MailHistory.mail_template.subject }}</td>
                                    <td id="history_box__subject--{{ MailHistory.id }}"><a href="#mailModal" data-toggle="modal" data-whatever="{{ MailHistory.id }}">{{ MailHistory.subject }}</a></td>
                                </tr>
                            {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div><!-- /.box-body --> 
        </div><!-- /.box --> 
    </div><!-- /.col --> 
</div>
{% endif %}
<div id="edit_wrap" class="row">
    <div id="edit_box" class="col-md-9">
        <form id="order-mail-form" class="form-horizontal" method="post" action="{{ url('admin_order_mail', {id : Order.id}) }}">
        {{ form_widget(form._token) }}
        <input id="mode" type="hidden" name="mode">
        <div id="edit_box__body" class="box">
            <div id="edit_box__header" class="box-header">
                <h3 class="box-title">メール配信</h3>
            </div><!-- /.box-header -->
            <div id="edit_box__body_inner" class="box-body">
                <div id="edit_box__template" class="form-group">
                    {{ form_label(form.template) }}
                    <div class="col-sm-9 col-lg-10">
                        {{ form_widget(form.template, {'id': 'template-change'}) }}
                        {{ form_errors(form.template) }}
                    </div>
                </div>
                <div id="edit_box__subject" class="form-group">
                    {{ form_label(form.subject) }}
                    <div class="col-sm-9 col-lg-10">
                        {{ form_widget(form.subject) }}
                        {{ form_errors(form.subject) }}
                    </div>
                </div>
                <div id="edit_box__item_header" class="form-group">
                    {{ form_label(form.header) }}
                    <div class="col-sm-9 col-lg-10">
                        {{ form_widget(form.header, {'attr': {'rows': '7'}}) }}
                        {{ form_errors(form.header) }}
                    </div>
                </div>
                <div id="edit_box__item_footer" class="form-group">
                    {{ form_label(form.footer) }}
                    <div class="col-sm-9 col-lg-10">
                        {{ form_widget(form.footer, {'attr': {'rows': '7'}}) }}
                        {{ form_errors(form.footer) }}
                    </div>
                </div>
                <div class="extra-form">
                    {% for f in form.getIterator %}
                        {% if f.vars.name matches '[^plg*]' %}
                            {{ form_row(f) }}
                        {% endif %}
                    {% endfor %}
                </div>
            </div><!-- /.box-body -->
        </div><!-- /.box -->
        <div id="edit_box__footer" class="row">
            <div id="button_box__button_menu" class="col-xs-10 col-xs-offset-1 col-sm-6 col-sm-offset-3 text-center btn_area">
                <button type="submit" class="btn btn-primary btn-lg" name="mode" value="confirm">送信内容を確認</button>
                <p><a href="{{ url('admin_order_page', { page_no: app.session.get('eccube.admin.order.search.page_no')|default('1') }) }}?resume=1">検索結果へ戻る</a></p>
            </div>
        </div>
        </form>

    </div><!-- /.col -->
</div>

{% endblock %}

{% block modal %}
<!-- Modal -->
<div class="modal fade" id="mailModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-body">
      </div>
      <div class="modal-footer hidden-print">
        <button type="button" class="btn btn-default" data-dismiss="modal">閉じる</button>
      </div>
    </div>
  </div>
</div>

{% endblock modal %}
